<template>
  <div class="container">
    <div>
      <el-row :gutter="12">
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="选择日期：">
              <el-date-picker
                v-model="form.valueDay"
                :type="form.typeDatePicker"
                :value-format="form.formatDatePicker"
                placeholder="选择日期"
                style="width: 180px"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form" style="float: left">
            <el-button size="mini" type="primary" @click="getDataReality"
              >查 询</el-button
            >
            <el-button size="mini" type="success" @click="exportExcel"
              >导 出</el-button
            >
          </el-form>
        </el-col>
      </el-row>
    </div>
    <el-table
    v-loading="loading"
      :data="
        tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
      "
    >
    <!-- LICENSE_PLATE	PARENT_NAME	CLIENT_NAME	STIME	ETIME	ALLTIME	SUMMILE	LENGTH	TIME
津C95726	碧海视频车	碧海视频车	2022-03-01 04:45:15.000	2022-03-01 21:13:57.000	219	64494	NULL	NULL -->
      <el-table-column
        prop="LICENSE_PLATE"
        label="车辆名称"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="CLIENT_NAME"
        label="分组名称"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="STIME"
        label="开始时间"
        align="center"
      ></el-table-column>
<el-table-column
        prop="ETIME"
        label="结束时间"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="ALLTIME"
        label="实际时间"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="SUMMILE"
        label="实际里程"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="TIME"
        label="计划时间"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="LENGTH"
        label="计划里程"
        align="center"
      ></el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="tableData.length"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import '@/assets/css/common.css'
import { formatDate } from '@/common/js/date.js'

import export2Excel from '@/utils/exportExcel/index.js'
export default {
  data () {
    return {
      loading: false,
      currentPage: 1, // 初始页
      pageSize: 10, //    每页的数据
      form: {
        radioData: '日',
        valueDay: '',
        valueDaySelect: '',
        valueMonth: '',
        valuePointID: '',
        valueType: '',
        typeDatePicker: 'date',
        formatDatePicker: 'yyyy-MM-dd',
        queryType: 1,
        queryTypeList: [{
          value: 1,
          label: '按日期查询'
        }, {
          value: 2,
          label: '按月份查询'
        }]
      },
      selectPointData: [],
      tableData: [],
      dialogDetail2Title: '',
      dialogDetail2Show: false,
      dialogDetail2Data: [],
      dialogDetail3Title: '',
      dialogDetail3Show: false,
      dialogDetail3Data: [],
      dialogDetail4Title: '',
      dialogDetail4Show: false,
      dialogDetail4Data: [],
      dialogDetail5Title: '',
      dialogDetail5Show: false,
      dialogDetail5Data: []
    }
  },
  created () {
    this.form.valueDay = formatDate(new Date(new Date() - 3600 * 1000 * 24), 'yyyy-MM-dd')
    this.form.valueMonth = formatDate(new Date(), 'yyyy-MM')
    this.getDataList()
  },
  methods: {
    async getDataList () {
      this.loading = true;
      var url = 'Kitchen/GetCarLengthAndTime?ClientNo=0&workdate=' + this.form.valueDay
      const { data } = await this.$Http.get(url)
      this.tableData = [];
      data.forEach(element => {
        if (element.TIME) {
          this.tableData.unshift(element)
        }else{
          this.tableData.push(element)
        }
      });
      this.loading = false;
    },
    // 导出Excel
    exportExcel () {
      const excelName = '规划路线分析'
      var tHeader = ['车辆名称', '分组名称', '开始时间', '结束时间', '实际时间', '实际里程', '计划时间', '计划里程']
      var filterVal = ['LICENSE_PLATE', 'CLIENT_NAME', 'STIME', 'ETIME', 'ALLTIME', 'SUMMILE', 'TIME', 'LENGTH']
      export2Excel(tHeader, filterVal, this.tableData, excelName)
    },
    handleEdit (index, row) {
      this.dialogDetail3Title = '垃圾点明细'
      this.dialogDetail3Data = row.DATAREAL
      this.dialogDetail3Show = true
    },
    // 分页导航
    handlePageChange (currentPage) {
      this.currentPage = currentPage
      // console.log(this.currentPage)
      // this.$set(this.query, 'pageIndex', val);
      // this.getData();
    },
    handleSizeChange (size) {
      this.pageSize = size
      console.log(this.pageSize)
    }
  }
}
</script>
<style>
.content {
  overflow-y: scroll;
}
.el-col-6 {
  min-width: 400px;
  min-height: 50px;
}
.el-table th {
  height: 40px;
}
/* 弹出框 */
.el-dialog {
  background: #ccd8e7;
  padding: 0px 10px 10px;
}
.el-dialog__title {
  color: #15428b;
  font-size: 16px;
  font-weight: 600;
}
.el-dialog__body {
  background: #dfe8f6;
  border: 1px solid #99bbe8;
}
.el-dialog__footer {
  padding: 10px 0px;
}
</style>
